/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import control.Archivo;
import control.MM1;
import javax.swing.ButtonModel;
import javax.swing.JOptionPane;
/**
 *
 * @author lOaD
 */
public class PanelMg1Ingresar extends javax.swing.JPanel {

    /**
     * Creates new form PanelMg1Ingresar
     */
    
    int valllegada = 1 ;
    int valatencion = 1 ;
    
    public PanelMg1Ingresar() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        RBtasaLlegada = new javax.swing.JRadioButton();
        RBtiempoLlegada = new javax.swing.JRadioButton();
        RBtasaAtencion = new javax.swing.JRadioButton();
        RBtiempoAtencion = new javax.swing.JRadioButton();
        TFatencion = new javax.swing.JTextField();
        TFllegada = new javax.swing.JTextField();
        BtAnalizar = new javax.swing.JButton();
        Btexportar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        TAresultados = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        LbProbabilidaes1 = new javax.swing.JLabel();
        TFn1 = new javax.swing.JTextField();
        Lbn1 = new javax.swing.JLabel();
        Lbmayor = new javax.swing.JLabel();
        Tfm1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        LbLlegada = new javax.swing.JLabel();
        LbAtencion = new javax.swing.JLabel();

        buttonGroup1.add(RBtasaLlegada);
        RBtasaLlegada.setSelected(true);
        RBtasaLlegada.setText("Tasa de Llegada");
        RBtasaLlegada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RBtasaLlegadaActionPerformed(evt);
            }
        });

        buttonGroup1.add(RBtiempoLlegada);
        RBtiempoLlegada.setText("Tiempo de Llegada");
        RBtiempoLlegada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RBtiempoLlegadaActionPerformed(evt);
            }
        });

        buttonGroup2.add(RBtasaAtencion);
        RBtasaAtencion.setSelected(true);
        RBtasaAtencion.setText("Tasa de Atención");
        RBtasaAtencion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RBtasaAtencionActionPerformed(evt);
            }
        });

        buttonGroup2.add(RBtiempoAtencion);
        RBtiempoAtencion.setText("Tiempos de Atención");
        RBtiempoAtencion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RBtiempoAtencionActionPerformed(evt);
            }
        });

        TFatencion.setName("Atencion");

        TFllegada.setName("Llegada");
        TFllegada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TFllegadaActionPerformed(evt);
            }
        });

        BtAnalizar.setText("Analizar");
        BtAnalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtAnalizarActionPerformed(evt);
            }
        });

        Btexportar.setText("Exportar");
        Btexportar.setEnabled(false);
        Btexportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtexportarActionPerformed(evt);
            }
        });

        TAresultados.setColumns(20);
        TAresultados.setRows(5);
        jScrollPane1.setViewportView(TAresultados);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        LbProbabilidaes1.setText("cálculo de Probabilidades");

        Lbn1.setText("Clientes en la cola");

        Lbmayor.setText(">");

        Tfm1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Tfm1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Media");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 26, Short.MAX_VALUE)
                        .addComponent(Lbmayor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(TFn1, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                            .addComponent(Tfm1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Lbn1)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(LbProbabilidaes1)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(LbProbabilidaes1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Lbn1)
                    .addComponent(Lbmayor))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Tfm1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(0, 51, Short.MAX_VALUE))
        );

        LbLlegada.setText("/hora");

        LbAtencion.setText("/hora");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(36, 36, 36)
                                .addComponent(BtAnalizar)
                                .addGap(18, 18, 18)
                                .addComponent(Btexportar))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(RBtiempoAtencion)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(RBtasaLlegada)
                                                .addGap(33, 33, 33)
                                                .addComponent(TFllegada, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(RBtiempoLlegada)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(RBtasaAtencion)
                                                .addGap(27, 27, 27)
                                                .addComponent(TFatencion, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 94, Short.MAX_VALUE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(LbAtencion)
                                            .addComponent(LbLlegada))))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(47, 47, 47))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(RBtasaLlegada)
                            .addComponent(TFllegada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(LbLlegada))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(RBtiempoLlegada)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(RBtasaAtencion)
                            .addComponent(TFatencion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(RBtiempoAtencion)
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(BtAnalizar)
                            .addComponent(Btexportar)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(64, 64, 64)
                        .addComponent(LbAtencion)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void RBtasaLlegadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RBtasaLlegadaActionPerformed
        LbLlegada.setVisible(true);
        valllegada = 1;
    }//GEN-LAST:event_RBtasaLlegadaActionPerformed

    private void RBtiempoLlegadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RBtiempoLlegadaActionPerformed
        LbLlegada.setVisible(false);
        valllegada = 0;

    }//GEN-LAST:event_RBtiempoLlegadaActionPerformed

    private void RBtasaAtencionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RBtasaAtencionActionPerformed
        LbAtencion.setVisible(true);
        valatencion = 1;
    }//GEN-LAST:event_RBtasaAtencionActionPerformed

    private void RBtiempoAtencionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RBtiempoAtencionActionPerformed
        LbAtencion.setVisible(false);
        valatencion = 0;

    }//GEN-LAST:event_RBtiempoAtencionActionPerformed

    private void BtAnalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtAnalizarActionPerformed
        boolean actatencion = MM1.revisarcampos(TFatencion);
        boolean actllegada = MM1.revisarcampos(TFllegada);
        boolean actn = MM1.revisarcampos(TFn1);
        boolean actt = MM1.revisarcampos(Tfm1);

        float vllegada = 0;
        float vatencion = 0;
        if (actatencion && actllegada && actn && actt) {
            if (valatencion == 1) {
                vatencion = Float.parseFloat(TFatencion.getText()) / 60;
            } else {
                vatencion = 1 / Float.parseFloat(TFatencion.getText());
            }
            if (valllegada == 1) {
                vllegada = Float.parseFloat(TFllegada.getText()) / 60;
            } else {
                vllegada = 1 / Float.parseFloat(TFllegada.getText());
            }
            if (vllegada / vatencion > 1) {
                JOptionPane.showMessageDialog(null, "Factor de Utilización del sistema mayor que 1, P:" + vllegada / vatencion);
            } else {
                MM1 mm1 = new MM1();
                double vn = Double.parseDouble(TFn1.getText());
                float vm = Float.parseFloat(Tfm1.getText());

                float matr[] = mm1.ModeloMg1(vllegada, vatencion, vm, vn);
                //JOptionPane.showMessageDialog(null,"Factor de Utilización del sistema P:"+vllegada/vatencion);
                imprimirMat(matr);
                Btexportar.setEnabled(true);
            }
        }

    }//GEN-LAST:event_BtAnalizarActionPerformed

    private void BtexportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtexportarActionPerformed
        //Archivo.GrabarArchivo("MM1",matr);
    }//GEN-LAST:event_BtexportarActionPerformed

    private void TFllegadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TFllegadaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TFllegadaActionPerformed

    private void Tfm1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Tfm1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Tfm1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtAnalizar;
    private javax.swing.JButton Btexportar;
    private javax.swing.JLabel LbAtencion;
    private javax.swing.JLabel LbLlegada;
    private javax.swing.JLabel LbProbabilidaes1;
    private javax.swing.JLabel Lbmayor;
    private javax.swing.JLabel Lbn1;
    private javax.swing.JRadioButton RBtasaAtencion;
    private javax.swing.JRadioButton RBtasaLlegada;
    private javax.swing.JRadioButton RBtiempoAtencion;
    private javax.swing.JRadioButton RBtiempoLlegada;
    private javax.swing.JTextArea TAresultados;
    private javax.swing.JTextField TFatencion;
    private javax.swing.JTextField TFllegada;
    private javax.swing.JTextField TFn1;
    private javax.swing.JTextField Tfm1;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

private void imprimirMat(float[] matr) {
        String textores = "";
        textores = textores + "Ls : "+matr[1]+ "-Clientes esperados en el sistema " + "\n";
        textores = textores + "Lq : "+matr[2]+ " Clientes esperados en cola "+ "\n";
        textores = textores + "Ws : "+matr[3]+ "min " +"-Tiempo esperado de espera en el sistema "+"\n";
        textores = textores + "Wq : "+matr[4]+ "min " +"-Tiempo esperado de espera en cola "+"\n";
        textores = textores + "Pn : "+matr[5]+ " Probabilidad de tener "+ TFn1.getText() +" clientes"+"\n";
        textores = textores + "Pw : "+matr[6]+ " Probabilidad de que un cliente espere por el servicio "+"\n";
        
       TAresultados.setText(textores);
       
    }


}
